import javafx.scene.control.SelectionMode;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-14
 * Time: 11:14
 */
public class Demo6 {
    public static int count=1;
    public static void main(String[] args) {
        BlockingQueue<Integer> queue =new ArrayBlockingQueue<>(100);
        Thread t1=new Thread(()->{
            while(true){
                try {
                    queue.put(count);
                    System.out.println("t1 生产:"+count);
                    Thread.sleep(1000);
                    count++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


            }

        });
        Thread t2=new Thread(()->{
            while(true){
                try {
                    int elem=queue.take();
                    System.out.println("t2消费 :"+ elem);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }



            }
        });
        t1.start();
        t2.start();


    }
}
